
package com.contractmodule.servlet;
import com.contractmodule.bean.TbDispatchListProductPrice;
import com.contractmodule.dao.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import util.*;

public class TbDispatchListProductPriceServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
      /*  String dispatchListCode=request.getParameter("dispatchListCode");
        int productId=Integer.parseInt(request.getParameter("productId"));

            if(new TbDispatchListProductPriceDAO().add(new TbDispatchListProductPrice(dispatchListCode,productId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);*/
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_DispatchListProductPrice", "DispatchListProductPriceId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int dispatchListProductPriceId=Integer.parseInt(request.getParameter("dispatchListProductPriceId"));
        String dispatchListCode=request.getParameter("dispatchListCode");
        int productId=Integer.parseInt(request.getParameter("productId"));

            if(new TbDispatchListProductPriceDAO().edit(new TbDispatchListProductPrice(dispatchListProductPriceId,dispatchListCode,productId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response); 
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbDispatchListProductPrice",new TbDispatchListProductPriceDAO().getTbDispatchListProductPriceByDispatchListProductPriceId(Integer.parseInt(request.getParameter("dispatchListProductPriceId"))));
            response.sendRedirect("ContractModule/TbDispatchListProductPriceOperate.jsp");
    	}
        if("showadd".equals(method)){
            
            request.getSession(true).removeAttribute("tbDispatchListProductPrice");
            response.sendRedirect("ContractModule/TbDispatchListProductPriceOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getSession(true).setAttribute("tbDispatchListProductPriceList",new TbDispatchListProductPriceDAO().getTbDispatchListProductPriceAll());
        response.sendRedirect("ContractModule/TbDispatchListProductPriceList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }
}
